<?php
/**
 * CreateTime: 2023/11/21 14:06
 * User:LinQ
 */

namespace App\Models\Auth;

use App\Models\BasicModel;

class RoleAuthModel extends BasicModel
{
    protected $table = 'role_auth';

    protected $primaryKey = 'role_auth_id';

    protected $fillable = [
        'role_auth_id',
        'role_id',
        'auth_id',
        'auth_value',
        'created_at',
        'updated_at',
    ];

    protected $casts = [
        'role_auth_id' => 'integer',
        'role_id' => 'integer',
        'auth_id' => 'integer',
        'auth_value' => 'integer',
        'created_at' => 'string',
        'updated_at' => 'string',
    ];

    protected $hidden = [
        'created_at',
        'updated_at',
    ];

    /**
     * 通过角色组和权限获取权限最大的权限位
     * @param $roles
     * @param $auth_id
     * @return int
     */
    public function getRoleAuthByRolesAndAuthId($roles,$auth_id){
        return $this
            ->whereIn('role_id',$roles)
            ->where('auth_id',$auth_id)
            ->max('auth_value');
    }

}